//
//  ThreeViewController.m
//  DLSlideController
//
//  Created by Dongle Su on 14-12-6.
//  Copyright (c) 2014年 dongle. All rights reserved.
//

#import "ZhaoPinViewController.h"
#import "ZPDetailViewController.h"
#import "CompanyZhaoPinModel.h"

#import "ZhaoPinTableViewCell.h"

@interface ZhaoPinViewController ()<UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate>

{
    NSMutableArray * DataArray;
    

}

@end

@implementation ZhaoPinViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    DataArray = [[NSMutableArray alloc]init];
    
   
    
    self.JianJieTableView.delegate = self;
    self.JianJieTableView.dataSource = self;
    
   
    
    self.JianJieTableView.tableHeaderView =[self creatHeader];
    
    self.JianJieTableView.tableFooterView = [UIView new];
    
    
    [self.JianJieTableView registerNib:[UINib nibWithNibName:@"ZhaoPinTableViewCell" bundle:nil] forCellReuseIdentifier:@"zhaopin"];
    
    
    if ([self isLogin]) {
     
        [U76HONet CompanyZhaoPinAction:@"" code:self.yqCode ucode:[Singleton share].code withPage:@"1" withPnum:@"8" andDataBlock:^(id obj) {
            
            DataArray = obj;
            
            [self.JianJieTableView reloadData];
            
            
        }];
        
    }
    
    
    
    
    
    
    // Do any additional setup after loading the view from its nib.
    NSLog(@"three didload");
}
-(BOOL)isLogin
{
    if ([Singleton share].code) {
        NSLog(@"登录了");
        return YES;
        
    }
    else
    {
        //        NSLog(@"还没登录呢");
        //        LoginViewController * loginVC = [[LoginViewController alloc]init];
        //        [self.navigationController pushViewController:loginVC animated:NO];
        //        return NO;
        if (SYSTEM_VERSION >= 8.0) {
            UIAlertController * alerVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"您还没有登录是否登录" preferredStyle:UIAlertControllerStyleAlert];
            [alerVC addAction:[UIAlertAction actionWithTitle:@"登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                
                LoginViewController * loginVC = [[LoginViewController alloc]init];
                UINavigationController *nvc = [[UINavigationController alloc]initWithRootViewController:loginVC];
                nvc.navigationBarHidden = YES;
                
                [self presentViewController:nvc animated:YES completion:nil];
            }]];
            [alerVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                
            }]];
            [self.view.window.rootViewController presentViewController:alerVC animated:YES completion:nil];
            
        }
        else
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您还没有登录是否登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [alert show];
        }
        return NO;
        
    }
}
#pragma mark --footView的高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
   
    
    return 30;
    
}
#pragma mark 头标题视图
-(UIView *)creatHeader{
    
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 40)];
    
    view.backgroundColor  = [UIColor whiteColor];
    
    UIImageView * leftImageView = [[UIImageView alloc]initWithFrame:CGRectMake(20,12 ,15 , 15)];
    
    leftImageView.image = [UIImage imageNamed:@"00a"];
    
    [view addSubview:leftImageView];
    
    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(40, 10, 200, 20)];
    label.font = [UIFont systemFontOfSize:15];
    label.text = @"招聘职位";
    
    label.textColor = [UIColor colorWithRed:0.75 green:0.84 blue:0.55 alpha:1.00];
    
    [view addSubview:label];
    
    return view;
    



}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return  DataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    ZhaoPinTableViewCell * cell = [self.JianJieTableView dequeueReusableCellWithIdentifier:@"zhaopin"];
    
    if (DataArray.count!=0) {
        cell.zhaoPinModel = DataArray[indexPath.row];
    }
   
    
    
    
    
    
    return cell;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 150;


}


-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    
    return nil;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    ZPDetailViewController * zpDetailVC = [[ZPDetailViewController alloc]init];
    
  CompanyZhaoPinModel * zhaoPinModel = DataArray[indexPath.row];
    zpDetailVC.dutyId = zhaoPinModel.Jid;
    [self.navigationController pushViewController:zpDetailVC animated:YES];

}



- (void)didReceiveMemoryWarning{
    [super didReceiveMemoryWarning];
    NSLog(@"three didReceiveMemoryWarning");
}
- (void)dealloc{
    NSLog(@"three dealloc");
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
